<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>01.vue中组件回顾</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css">

</head>
<body>
<div id="app">



    <router-link to="/login?id=21&name=zhangsan">我要登录</router-link>
    <router-link to="/register/24/张三">我要注册</router-link>

    <router-view></router-view>

</div>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="./js/vue-router.js"></script>
<!--<script src="https://unpkg.com/axios/dist/axios.min.js"></script>-->
<script>

    //声明组件模板
    const login = {
        template:'<h1>用户登录{{ this.$route.query.id }} {{ this.$route.query.name }}</h1>',
        data(){return {}},
        methods:{},
        created(){
            console.log("=============>"+this.$route.query.id+"======>"+this.$route.query.name);
        }
    };

    const register = {
        template:'<h1>用户注册{{ $route.params.name }}</h1>',
        created(){
            console.log("注册组件中id:   "+this.$route.params.id+this.$route.params.name);
        }
    };

    //创建路由对象
    var router = new VueRouter({
        routes:[
            {path:'/',redirect:'/login'},
            {path:'/login',component:login},
            {path:'/register/:id/:name',component:register}
        ]
    });

    const app = new Vue({
        el: "#app",
        data: {},
        methods: {},
        router//注册路由对象
    });
</script>
</body>
</html>